home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DllSys_Files / QUICKPRO / QUICK.C
Encoding:
C/C++ Source or Header  |  2002-03-08  |  2.1 KB  |  57 lines

  1. // Dynamic link library implementation of NeuroSolutions Quickprop component
  2.  
  3. #include "NSDLL.h"
  4.  
  5. /*****************************/
  6. /* Gradient search procedure */
  7.  
  8. __declspec(dllexport) void performQuickprop(
  9.     DLLData    *instance,        // Pointer to instance data (may be NULL)
  10.     NSFloat    *weights,        // Pointer to the vector of weights
  11.     int        length,        // Length of the weight vector
  12.     NSFloat    *gradient,        // Pointer to the vector of gradients, one for each weight
  13.     NSFloat    *step,            // Pointer to the learning rate/s
  14.     BOOL    individual,        // Indicates whether their is one learning rate for all weights (FALSE),
  15.                     // or each weight has its own learning rate
  16.     int        stepDivisor,// The number each step size should be divided by
  17.     BOOL    decayWeights,    // TRUE if weight decay is active
  18.     NSFloat decayRate,    // Rate to decay weights if weight decay is active
  19.     NSFloat    *delta,            // Last weight Update
  20.     NSFloat    *momentum,        // Individual momentum rate for each weight
  21.     NSFloat    defaultMomentum,    // Max momentum rate for all weights
  22.     NSFloat    *lastGradient        // Previous weight gradient vector
  23.     )
  24. {
  25.     register int i;
  26.  
  27.     for (i=0; i<length; i++) {
  28.         momentum[i] = gradient[i]/(lastGradient[i] - gradient[i]);
  29.         if (momentum[i] > defaultMomentum)
  30.             momentum[i] = defaultMomentum;
  31.         if (momentum[i] < -defaultMomentum)
  32.             momentum[i] = -defaultMomentum;
  33.         delta[i] = momentum[i]*delta[i] + lastGradient[i]*(gradient[i]<0?0:(step[individual?i:0]/stepDivisor)*gradient[i]);
  34.         weights[i] += delta[i] - (decayWeights ? weights[i] * decayRate : 0.0f);
  35.         lastGradient[i] = gradient[i];
  36.     }
  37. }
  38.  
  39. /******************************************/
  40. /* Management of instance data (OPTIONAL) */
  41. /*
  42. __declspec(dllexport) DLLData *allocQuickprop(
  43.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  44.     int    length,        // Length of the weight vector
  45.     BOOL    individual    // Indicates whether their is one learning rate for all weights (FALSE),
  46.                 // or each weight has its own learning rate
  47.     )
  48. {
  49.     DLLData *instance = allocDLLInstance(oldInstance);
  50.     return instance;
  51. }
  52.  
  53. __declspec(dllexport) void freeQuickprop(DLLData *instance)
  54. {
  55.     freeDLLInstance(instance);
  56. }
  57. */